<?xml version="1.0" encoding="UTF-8"?>
<!--

       Copyright 2006-2016 the original author or authors.

       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>The &lt;javaModelGenerator&gt; Element</title>
    <link rel="stylesheet" type="text/css" href="../mbgstyle.css"/>
</head>
<body>
<h1>The &lt;javaModelGenerator&gt; Element</h1>
<p>The &lt;javaModelGenerator&gt; element is used to define properties of the Java model
    generator. The Java Model Generator builds primary key classes, record classes, and
    Query by Example classes that match the introspected table. This element is a required
    child element
    of the <a href="context.html">&lt;context&gt;</a> element.</p>
<h2>Required Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
    <tr>
        <th>Attribute</th>
        <th>Description</th>
    </tr>
    <tr>
        <td valign="top">targetPackage</td>
        <td>This is the package where the generated classes will be placed. In
            the default generator, the property "enableSubPackages"
            controls how the actual package is calculated. If true,
            then the calculated package will be the targetPackage plus
            sub packages for the table's catalog and schema if they exist.
            If false (the default) then the calculated package will be
            exactly what is specified in the targetPackage attribute.
            MyBatis Generator will create folders as required for the generated
            packages.
        </td>
    </tr>
    <tr>
        <td valign="top">targetProject</td>
        <td>This is used to specify a target project for the
            generated objects. When running in the Eclipse
            environment, this specifies the project and source folder where
            the objects will be saved.
            In other environments, this value should be an existing directory
            on the local file system. MyBatis Generator will not create this directory if
            it does not exist.
        </td>
    </tr>
</table>

<h2>Optional Attributes</h2>
<p>None</p>

<h2>Child Elements</h2>
<ul>
    <li><a href="property.html">&lt;property&gt;</a> (0..N)</li>
</ul>

<h2>Supported Properties</h2>
<p>This table lists the properties of the default Java model generators that can be
    specified with the <a href="property.html">&lt;property&gt;</a> child element:</p>
<table border="1" cellspacing="0" cellpadding="5">
    <tr>
        <th>Property Name</th>
        <th>Property Values</th>
    </tr>
    <tr>
        <td valign="top">constructorBased</td>
        <td>
            This property is used to select whether MyBatis Generator will generate a constructor
            for the class that accepts a value for each field in the class. Also, the SQL result map
            will be built to use the constructor rather than the "setter" for each field.
            <p>This property is only applicable for MyBatis3 and will be ignored for
                iBATIS2.</p>
            <p>This property is ignored (and forced "true") if the "immutable" property
                is set "true".</p>
            <p>This property can be overridden by the corresponding property in a
                <a href="table.html">&lt;table&gt;</a> element.</p>
            <p><i>The default value is false.</i></p></td>
    </tr>
    <tr>
        <td valign="top">enableSubPackages</td>
        <td>This property is used to select whether MyBatis Generator will generate different
            Java packages for the objects based on the catalog and schema of the
            introspected table.
            <p>For example, suppose a table MYTABLE in schema MYSCHMA.
                Also suppose that the targetPackage attribute is set to "com.mycompany".
                If this property is true, the generated objects for the table will be placed in
                the package "com.mycompany.myschema". If the property is false, the generated
                objects will be placed in the "com.mycompany" schema.</p>
            <p><i>The default value is false.</i></p></td>
    </tr>
    <tr>
        <td valign="top">immutable</td>
        <td>
            This property is used to select whether MyBatis Generator will generate immutable
            model classes - this means that the classes will not have "setter" methods and
            the constructor will accept values for each field in the class.
            <p>If true, this forces the model classes to be built with paramterized constructors
                regardless of the value of the "constructorBased" property.</p>
            <p>This property is only applicable for MyBatis3 and will be ignored for
                iBATIS2.</p>
            <p>This property can be overridden by the corresponding property in a
                <a href="table.html">&lt;table&gt;</a> element.</p>
            <p><i>The default value is false.</i></p></td>
    </tr>
    <tr>
        <td valign="top">rootClass</td>
        <td>This property can be used to specify a root class for all generated
            Java model objects. MyBatis Generator will specify this value as the super class
            of the primary key object, if the table has a primary key, or the
            record object otherwise. This value may be overridden by specifying
            the <code>rootClass</code> property on a Table configuration.
            <p><b>Important:</b> If MyBatis Generator is able to load the root class, then it
                will not override a property in the root class that exactly matches a
                property that would normally be generated.
                An exact match of a property is defined as follows</p>
            <ul>
                <li>Property name matches exactly</li>
                <li>Property is of the same type</li>
                <li>Property has a "getter" method</li>
                <li>Property has a "setter" method</li>
            </ul>
            <p>If specified, the value of this property should be a fully qualified
                class name (like com.mycompany.MyRootClass).</p></td>
    </tr>
    <tr>
        <td valign="top">trimStrings</td>
        <td>
            This property is used to select whether MyBatis Generator adds code to trim
            the white space from character fields returned from the database.
            This can be useful if your database stores data in CHAR fields rather than
            VARCHAR fields. When true, MyBatis Generator will insert code to trim character fields.
            Can be overridden with the <code>trimStrings</code> property in a
            <a href="table.html">&lt;table&gt;</a> or
            <a href="columnOverride.html">&lt;columnOverride&gt;</a> element.
            <p><i>The default value is false.</i></p></td>
    </tr>
</table>

<h2>Example</h2>
<p>This element specifies that we always want to place generated classes
    in the "'test.model" package and that we want to use subpackages based on the
    table schema and catalog. We also want String columns trimmed.</p>
<pre>
&lt;javaModelGenerator targetPackage="test.model"
     targetProject="\MyProject\src"&gt;
  &lt;property name="enableSubPackages" value="true" /&gt;
  &lt;property name="trimStrings" value="true" /&gt;
&lt;/javaModelGenerator&gt;
</pre>

</body>
</html>
